package exception;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/*在IO中使用异常处理机制*/
public class FinallyDemo2 {
    public static void main(String[] args) {
        FileOutputStream fos = null;
        try{
            fos = new FileOutputStream("src/Exception/fos.dat");
            fos.write(1);
        }catch (FileNotFoundException e){
            System.out.println("文件未成功创建");
        } catch(IOException e){
            e.printStackTrace();
        }finally {
            try{
                if (fos != null){
                    fos.close();
                }
            }catch (IOException e){
                e.printStackTrace();
            }
        }
    }
}
